//
//  SeeImgsVC.m
//  NtoccShipper
//
//  Created by mac on 2019/12/26.
//  Copyright © 2019 zhuchongjin. All rights reserved.
//

#import "SeeImgsVC.h"
#import "XLImageViewer.h"

@interface SeeImgsVC (){
    UIView *_imgParent;
}
@property (nonatomic,strong) NSMutableArray *list;
@end

@implementation SeeImgsVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setTitleName:self.strTitle];
    [self setBackLeftButton:@""];
    
    // 过滤空字符
    
    self.list = [[NSMutableArray alloc]init];
    for (int i = 0; i < self.arrImgs.count; i++) {
        
        if ([CJControl getIsEmpty:self.arrImgs[i]]) {
        }else{
            [self.list addObject:self.arrImgs[i]];
        }
    }

    if (self.list.count > 0) {
        [self createView];
    }
}

/// 创建tableview 等
- (void)createView{

    CGRect rcFrame = CGRectMake(0, kTopHeight, kScreenWidth, 0);
    FlexFrameView *header = [[FlexFrameView alloc] initWithFlex:@"SeeImgsTopView" Frame:rcFrame Owner:self];
    header.flexibleHeight = YES;
    
    for (int i = 0; i < self.list.count; i++) {
        
        UIImageView* cell = [[UIImageView alloc]init];
        cell.userInteractionEnabled = YES;
//        [cell enableFlexLayout:YES];
         UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickToSeeBigCell:)];
        cell.tag = i + 1000;
        [cell enableFlexLayout:YES];
        [cell addGestureRecognizer:tap];
        
        [cell setLayoutAttrStrings:@[
                                     @"width",@"75",
                                     @"height",@"75",
                                     @"margin",@"1%",
                                     @"alignItems",@"center",
                                     @"justifyContent",@"center",
                                     ]];
        [cell setViewAttr:@"bgColor" Value:@"#E4E9ED"];
        [cell setViewAttr:@"borderRadius" Value:@"0"];
        [_imgParent insertSubview:cell atIndex:i];
        [_imgParent markDirty];

        [cell sd_setImageWithURL:[NSURL URLWithString:self.list[i]] placeholderImage:[UIImage imageNamed:@"zcj_error_image"]];
    }
    
    [header layoutIfNeeded];
    [self.view addSubview:header];
}

-(void)clickToSeeBigCell:(UIGestureRecognizer*)sender{
    UIView* cell = sender.view;
    [[XLImageViewer shareInstanse] showNetImages:self.list index:(int)cell.tag - 1000 fromImageContainer:cell];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
